package com.test13;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class MyTest_04 {

    public static void main(String[] args) {
        // test1();
        test2();
    }

    public static void test1() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int x = 0; x < 10; x++) {
            new Thread(() -> {
                try {
                    System.out.printf("【%s】%s%n", Thread.currentThread().getName(), sdf.parse("2022-07-30 15:02:24"));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }, "线程-" + x).start();
        }
    }

    public static void test2() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        ZoneId zoneId = ZoneId.systemDefault();
        for (int x = 0; x < 10; x++) {
            new Thread(() -> {
                LocalDateTime localDateTime = LocalDateTime.parse("2022-07-30 15:02:24", formatter);
                Instant instant = localDateTime.atZone(zoneId).toInstant();
                Date date = Date.from(instant);
                System.out.printf("【%s】%s%n", Thread.currentThread().getName(), date);
            }, "线程-" + x).start();
        }
    }
}
